<template>
  <router-layout>
    <div class="gainHome">
      <div class="banner">
        <img
          class="image"
          src="https://gw.alicdn.com/tfs/TB1oqBkOhTpK1RjSZR0XXbEwXXa-750-340.png"
          alt
        >
        <div class="integralDetail" @click="Link()">积分明细</div>
        <div class="text">
          <p style="text-align:center; font-size:43px">{{integral}}</p>
          <p style="text-align:center;">我的积分</p>
        </div>
        <div></div>
      </div>
      <div class="list">
        <div v-for="item in dataList" :key="item.id">
          <p class="name">{{item.module_name}}</p>
          <div class="taskList">
            <div
              v-for="it in item.rows"
              :key="it.id"
              class="van-hairline--bottom"
              style="margin:0 15px; display: flex;justify-content: space-between;padding:10px 0;"
            >
              <div class="lsitLeft">{{it.behavior_desc}}</div>
              <div class="listRight">
                <p class="num">+{{it.score}}积分</p>
                <p class="botton" @click="openLink(it)" v-if="it.complete == 0">去完成</p>
                <p class="botton1" @click="openLink(it)" v-if="it.complete == 1">已完成</p>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </router-layout>
</template>
<script>
import { listBehavior, AmountntegralRecord } from "@/api/admin";
import TitleItem from "../../components/public/title/title";
import { compare } from "semver";

export default {
  name: "component_name",
  components: { TitleItem },
  data() {
    return {
      classA: false,
      dataList: "",
      integral: ""
    };
  },
  methods: {
    openLink(e) {
      if (e.complete == 1) {
        this.$toast.fail("任务不能重复完成");
        return;
      }
      if (e.module_name == "论坛") {
        this.$router.push({
          path: "/CommunityHome",
          query: { nameLink: "articleAdd" }
        });
      }
      if (e.module_name == "活动") {
        this.$router.push("/ActivityHome");
      }
      if (e.module_name == "合理化建议") {
        this.$router.push({
          path: "/proposalHome",
          query: { nameLink: "proposalAdd" }
        });
      }
      if (e.module_name == "抽奖") {
        this.$router.push("/LuckyDraw");
      }
      if (e.module_name == "投票") {
        this.$router.push("/VoteHome");
      }
      if (e.module_name == "问卷") {
        this.$router.push("/SurveyHome");
      }
      if (e.module_name == "签到") {
        this.$router.push("/Signin");
      }
    },
    Link() {
      this.$router.push("/Integral");
    },
    async initList() {
      let { data } = await listBehavior();
      if (data.status == 100) {
        this.dataList = data.data;
        this.dataList.map(item => {
          item.rows.forEach(it => {
            if (it.complete == 1) {
              this.classA = true;
            }
          });
        });
      }
    },
    async Amountntegral() {
      let { data } = await AmountntegralRecord();
      this.integral = data.data.amonutScore;
      localStorage.setItem("integral", this.integral);
    }
  },
  created: function() {
    this.Amountntegral();
    this.initList();
  }
};
</script>
<style lang="scss" scoped>
.list {
  background: #f5f5f5;
  padding-bottom: 20px;
}
.banner {
  position: relative;
  width: 100%;
  overflow: hidden;
  .image {
    width: 100%;
  }
  .integralDetail {
    top: 10%;
    right: -3%;
    background: #ec6f6f;
    border-radius: 16px;
    position: absolute;
    font-size: 16px;
    color: #ffffff;
    width: 106px;
    height: 32px;
    text-align: center;
    line-height: 32px;
  }
  .text {
    font-size: 15px;
    color: #ffffff;
    position: absolute;
    top: 20%;
    right: 41%;
  }
}
.list {
  .taskList {
    background: #fff;
    .lsitLeft {
      font-size: 16px;
      color: #4a4a4a;
    }
    .listRight {
      display: flex;
      .botton {
        border: 1px solid #ec6f6f;
        border-radius: 12px;
        width: 58px;
        height: 24px;
        font-size: 12px;
        color: #ec6f6f;
        text-align: center;
        line-height: 24px;
      }
      .botton1 {
        border: 1px solid #cccdd5;
        border-radius: 12px;
        width: 58px;
        height: 24px;
        font-size: 12px;
        color: #a0a0a0;
        text-align: center;
        line-height: 24px;
      }
      .num {
        font-size: 12px;
        color: #f88581;
        margin-right: 10px;
        margin-top: 3px;
      }
    }
  }
}
.name {
  font-size: 18px;
  padding: 6px 15px;
}
</style>
